<?php

class ZoneNameController extends GxController {
    
    public function filters() {
        return array('rights');
    }
    
    public function actionView($id) {
        $this->render('view', array(
            'model' => $this->loadModel($id, 'ZoneName'),
        ));
    }

    public function actionCreate() {
        $model = new ZoneName;
        if (isset($_POST['ZoneName'])) {
            $model->setAttributes($_POST['ZoneName']);

            if ($model->save()) {
                if (Yii::app()->getRequest()->getIsAjaxRequest())
                    Yii::app()->end();
                else
                    $this->redirect(array('view', 'id' => $model->id));
            }
        }

        $this->render('create', array('model' => $model));
    }

    public function actionUpdate($id) {
        $model = $this->loadModel($id, 'ZoneName');
        if (isset($_POST['ZoneName'])) {
            $model->setAttributes($_POST['ZoneName']);
            if ($model->save()) {
                $this->redirect(array('view', 'id' => $model->id));
            }
        }
        $this->render('update', array(
            'model' => $model,
        ));
    }

    public function actionAdmin() {
        $model = new ZoneName('search');
        $model->unsetAttributes();
        $statuschangeurl = Yii::app()->createUrl('zonename/statuschange/');
        if (isset($_GET['ZoneName']))
            $model->setAttributes($_GET['ZoneName']);
        $this->render('admin', array(
            'model' => $model, 'statuschangeurl' => $statuschangeurl
        ));
    }

    public function actionState() {
        $data = State::model()->findAll('country_id=:country_id AND is_active=:is_active', array(':country_id' => (int) $_POST['ZoneName']['country_id'], 'is_active' => '1'));
        $data = CHtml::listData($data, 'id', 'name');
        foreach ($data as $value => $name) {
            echo CHtml::tag('option', array('value' => $value), CHtml::encode($name), true);
        }
    }

    public function actionCity() {
        $data = City::model()->findAll('state_id=:state_id AND status=:status', array(':state_id' => (int) $_POST['ZoneName']['state_id'], 'status' => '1'));
        $data = CHtml::listData($data, 'id', 'city_name');
        $dataValue = CHtml::tag('option', array('value' => ''), CHtml::encode('Select City name'), true);
        foreach ($data as $value => $name) {
            $dataValue.= CHtml::tag('option', array('value' => $value), CHtml::encode($name), true);
        }
        echo $dataValue;
    }

    public function actionStatuschange() {
        $model = $this->loadModel($_POST['id'], 'ZoneName');
        $model->status = $_POST['status'];
        $model->save();
    }

}